<?php if (!defined('THINK_PATH')) exit(); if($isAjax): ?><!DOCTYPE html>
<html>
    <head>
        <title><?php echo ($title); ?></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="generator" content="GodSon" />
        <meta name="author" content="LUCAS"/>
        <link rel="stylesheet" href="__ROOT____THM__/bootstrap/easyui.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="__ROOT____THM__/bootstrap/bootstrap.css"  type="text/css" media="screen" >

        <link rel="stylesheet" href="__ROOT____THM__/icon.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="__ROOT____CSS__/css.css" type="text/css" media="screen" />

        <script type="text/javascript" src="__ROOT____JS__/core/easyui1.4/jquery.min.js"></script>
        <script type="text/javascript" src="__ROOT____JS__/core/easyui1.4/jquery.easyui.min.js"></script>

        <script type="text/javascript" src="__ROOT____JS__/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript" src="__ROOT____JS__/core/btutil.js"></script>
        <script type="text/javascript" src="__ROOT____JS__/My97DatePicker/WdatePicker.js"></script>



        <script>
            var _ROOT_ = '__ROOT__';
        </script>



    </head>
    <body>
        <div id="bt_loading" class="loading"></div>
        <div id="bt_loading_progress" class="progress">执行中...</div><?php endif; ?>
<div class="easyui-layout" fit="true">
    <div region="north" style="height: 70px;border-bottom: none;">
    <script type="text/javascript">
    // function(){$('#dd').dialog('close');}
    </script>
        <form id="bt_export_search_from">
            <table style="height: 100%;">
                <tr>
                    <td><select class="easyui-combobox" data-options="panelHeight:'auto',editable:false,onChange:function(o,n){
                                if(o == '发票号'){$('#bt_export_input_name').attr('name','Q_invoice_like')}else{
                                $('#bt_export_input_name').attr('name','Q_报关单_like')
                                }
                                }"><option>报关单号</option><option>发票号</option></select></td>
                    <td><input  type="text" name="Q_报关单_like" id="bt_export_input_name"></td>
                    <td>客户</td>
                    <td><input  type="text" name="Q_addre_like"></td>
                    <td rowspan="2"><a href="javascript:void(0)" class="easyui-linkbutton" id="bt_export_search_btn">查询</a> <a href="javascript:$('#bt_export_search_from').form('clear');" class="easyui-linkbutton">清空</a> </td>
                </tr>
                <tr>
                    <td>发货时间</td>

                    <td><input  class="easyui-datebox" type="text" name="Q_fhdate_EGT" value="<?php echo date('Y-m-d',time()-3000000);?>" maxDate="#F{ $dp.$D('bt_export_input_fhdate_ed')||'2014-10-1'}" id="bt_export_input_fhdate_st"></td>
                    <td align="center">-</td>
                    <td><input class="easyui-datebox" type="text" name="Q_fhdate_LT" minDate="#F{ $dp.$D('bt_export_input_fhdate_st')}" id="bt_export_input_fhdate_ed"></td>
                </tr>
            </table>
        </form>
    </div>
    <div id="dd" ></div>
    <div region="center"class="font-size:100px;" ><table id="bt_export_grid" ></table></div>
</div>
<script type="text/javascript"> NameSpace("BT.export", function() { var context = this; var $grid = $('#bt_export_grid');
var viewDialog=$('#dd');

context.ready = function() {
    $grid.datagrid({
        fit: true,
        border: true,
        // width:'95%',
        // height:'500',
        nowrap: true,
        autoRowHeight: true,
        striped: true,
        collapsible:true,
        sortName: 'ID',
        sortOrder: 'desc',
        remoteSort: false,
        idField:'ID',
        url: _ROOT_ + '/export/getData',
        pagination: true,
        columns: [[
                {field:'ck',checkbox: true}, 
               // {field: 'ID', title: 'ID' ,align:'center'},
                {field: '手册号', title: '手册号' ,align:'center'},
                {field: '自编号', title: '自编号' ,align:'center'},
                {field: '报关单', title: '报关单' ,align:'center'},
                {field: 'invoice', title: '发票' ,align:'center', sortable: true},
                {field: 'TRACK', title: '运单号' ,align:'center'},
                {field: 'fhdate', title: '发货时间' ,align:'center', sortable: true},
                {field: 'SOT23QTY', title: 'SOT23QTY' ,align:'center'},
                {field: 'SOT89QTY', title: 'SOT89QTY' ,align:'center'},
                {field: 'EP3QTY', title: 'EP3QTY' ,align:'center'},                
                {field: 'SOT23MY', title: 'SOT23MY' ,align:'center'},                
                {field: 'SOT89MY', title: 'SOT89MY' ,align:'center'},
                {field: 'EP3MY', title: 'EP3MY' ,align:'center'},
                {field: 'addre', title: 'addre' ,align:'center', sortable: true},
                {field: 'Carrier', title: 'Carrier' ,align:'center'},
                {field: '备注', title: '备注' ,align:'center'},
                {field: '金额', title: '金额' ,align:'center'},
                {field: 'ID', title: '操作',  align: 'center', formatter: function(value) {
                                        return '<span title="编辑" class="img-btn icon-edit" ID=' + value + '></span>';
                }}
            ]],
        toolbar: [{
                text: '新增',
                iconCls: 'icon-add',
                handler: context.addView
            }, {
                text: '删除',
                iconCls: 'icon-remove',
                handler: context.doDelete
            }],
        onLoadSuccess: function() {
            var $bodyView = $grid.data('datagrid').dc.view2;
            $bodyView.find('span[ID]').click(function(e) {
                e.stopPropagation();
                var uid = $(this).attr('ID');
                context.updateView(uid);
            });
        }
    });

    $('#bt_export_search_btn').click(function() {
        var map = $('#bt_export_search_from').toJson();
        for (var i = map.length - 1; i >= 0; i--) {
           alert(i.map[i]);
        };

        $grid.datagrid('load', $('#bt_export_search_from').toJson());
    });
};

context.addView = function() {

    viewDialog.dialog({
        title: '新增订单',
        href: _ROOT_ + '/export/toadd',
        width: 400,
        height: 500,
        maximizable: true,
        resizable: true,
        bodyStyle: {overflow: 'hidden'},
        buttons: [{
                text: '提交',
                handler: context.doSubmit
            }]
    });
};

context.updateView = function(id) {
    r= $grid.datagrid('getRowIndex',id);
    viewDialog.dialog({
        title: '编辑进口清单',
        href: _ROOT_ + '/export/toUpdate?ID=' + id,
        width: 400,
        height: 500,
        maximizable: true,
        resizable: true,
        bodyStyle: {overflow: 'hidden'},
        buttons: [{
                text: '上一条',
                handler: function(){
                    viewDialog.dialog('close');
                    $grid.datagrid('clearSelections',r);
                    if(r>0)r=r-1;$grid.datagrid('selectRow',r);
                    var selected=$grid.datagrid('getSelected');
                    id=selected.ID;
                    context.updateView(id);
                }
            },{
                text: '下一条',               
                handler:function(){
                    viewDialog.dialog('close');
                    $grid.datagrid('clearSelections',r);
                    if(r<$grid.datagrid('getRows').length-1)r=r+1;
                    $grid.datagrid('selectRow',r);
                    var selected=$grid.datagrid('getSelected');
                    id=selected.ID;
                    context.updateView(id);
                    // viewDialog.dialog({href:_ROOT_+'/export/toUpdate?ID='+selected.ID});
                }
            },{
                text: '提交',
                handler:function(){
                        $bt_export_from = $('#bt_export_from');
                        if ($bt_export_from.form('validate')) {
                        $.post(_ROOT_ + '/export/doSave', $bt_export_from.toJson(), function(rsp) {
                                if (rsp.status) {
                                    $grid.datagrid('reload');
                                    // viewDialog.dialog('close');
                                    // $grid.datagrid('clearSelections',r);
                                    // if(r>0)r=r-1;$grid.datagrid('selectRow',r);
                                    // var selected=$grid.datagrid('getSelected');
                                    // id=selected.ID;
                                    // context.updateView(id);
                                } else {
                                    $.alert(rsp.msg+'修改失败！');
                                }
                        }, "JSON");
                        }
                }
            }]
    });
};


context.doDelete = function() {
    var checked = $grid.datagrid('getChecked');
    if (checked && checked.length > 0) {
        $.confirm('确认删除？', function(r) {
            if (r) {
                var ids = [];
                $.each(checked, function() {
                    ids.push(this.ID);
                    // $.alert(this.ID);
                });
                $.post(_ROOT_ + '/export/doDelete', {ids: ids.join(',')}, function(rsp) {
                    if (rsp.status) {
                        $.alert("delete OK");
                        $grid.datagrid('reload');
                    } else {
                        $.alert(rsp.msg);
                    }
                }, 'JSON');
            }
        });
    }
};

context.doSubmit = function(){
    $bt_export_from = $('#bt_export_from');
    if ($bt_export_from.form('validate')) {
        $.post(_ROOT_ + '/export/doSave', $bt_export_from.toJson(), function(rsp) {
            if (rsp.status) {
                $grid.datagrid('reload');
                $.alert('修改成功！');
                viewDialog.dialog('close');
            } else {
                $.alert(rsp.msg+'修改失败！');
                viewDialog.dialog('close');
            }
        }, "JSON");
    }

};
 }); </script>